package com.sdp.right.flow;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.sdp.core.bizc.vo.Result;
import com.sdp.right.flow.dto.FlowParam;
import com.sdp.right.flow.service.ISysFlowService;


@RestController
@RequestMapping("/SysFlowController")
public class SysFlowController {
	
	@Autowired
	private ISysFlowService sysFlowService;

	@GetMapping(value = "/init")
	public Result<?> init(@RequestParam(name="templateNo",required=true) String templateNo) {
		if(StringUtils.isEmpty(templateNo)) {
			return Result.error("流程编号不存在");
		}
		return Result.ok(sysFlowService.initFlow(templateNo));
	}
	
	@GetMapping(value = "/getCurrentTask")
	public Result<?> getCurrentTask(@RequestParam(name="taskId",required=true) String taskId) {
		if(StringUtils.isEmpty(taskId)) {
			return Result.error("任务内码不存在");
		}
		return Result.ok(sysFlowService.getCurrentTask(taskId));
	}
	
	@GetMapping(value = "/getApprovedFlowTaskHis")
	public Result<?> getApprovedFlowTaskHis(@RequestParam(name="instanceId",required=true) String instanceId) {
		if(StringUtils.isEmpty(instanceId)) {
			return Result.error("任务实例不存在");
		}
		return Result.ok(sysFlowService.getApprovedFlowTaskHis(instanceId));
	}
	
	
	@PostMapping(value = "/startUpFlow")
	public Result<?> startUpFlow(@RequestBody FlowParam flowParam) {
		sysFlowService.startUpFlow(flowParam);
		return Result.ok();
	}
	
	@PostMapping(value = "/commit")
	public Result<?> commit(@RequestBody FlowParam flowParam) {
		sysFlowService.comitFlow(flowParam);
		return Result.ok();
	}
}
